//=============================================================================
 /*:
 * @plugindesc 枫之舞界面 - 对话选择窗口
 * @author 老饕
 * @version 1.0.0
 * @date 2020.3.1
 *
 * @param Button Image
 * @text 按钮图片
 * @desc 按钮图片
 * @default MenuButton_YN
*/
var Imported = Imported || {};
Imported.SWDA_MsgChoiceWindow = true;

var SWDA_MsgChoiceWindow = SWDA_MsgChoiceWindow || {};
var parameters = PluginManager.parameters('SWDA_MsgChoiceWindow');
SWDAWindowManager.YNButtonImage = String(parameters['Button Image'] || 'MenuButton_YN');
//=====================================================
// 对话窗口选择项：修改颜色

Window_ChoiceList.prototype.normalColor = function () {
  return this.textColor(15);
};
//=====================================================
// 对话窗口选择项：修改位置。（居中）
//=====================================================
SWDA_MsgChoiceWindow.updatePlacement = Window_ChoiceList.prototype.updatePlacement;
Window_ChoiceList.prototype.updatePlacement = function() {
    SWDA_MsgChoiceWindow.updatePlacement.call(this);
	

	/*
	var positionType = $gameMessage.choicePositionType();
	    switch (positionType) {
    case 0:
        this.x = 0;
        break;
    case 1:
        this.x = (Graphics.boxWidth - this.width) / 2;
        break;
    case 2:
        this.x = Graphics.boxWidth - this.width;
        break;
    }
    if (messageY >= Graphics.boxHeight / 2) {
        this.y = messageY - this.height;
    } else {
        this.y = messageY + this._messageWindow.height;
    }
	*/
	this.x = (Graphics.boxWidth - this.width) / 2;
	this.y = (Graphics.boxHeight - this.height) / 2;
};
//=====================================================
// 对话窗口选择项：修改尺寸
//=====================================================
Window_ChoiceList.prototype.maxChoiceWidth = function() {
    var maxWidth = 256;
    var choices = $gameMessage.choices();
    for (var i = 0; i < choices.length; i++) {
        var choiceWidth = this.textWidthEx(choices[i]) + this.textPadding() * 2;
        if (maxWidth < choiceWidth) {
            maxWidth = choiceWidth;
        }
    }
    return maxWidth;
};

Window_ChoiceList.prototype.windowWidth = function() {
    var width = this.maxChoiceWidth() + this.padding * 2;
    return Math.min(width, 768);
};
//=====================================================
// 对话窗口选择项：为标准Y/N选项时，改为另一个窗口
//=====================================================
Window_Message.prototype.startInput = function() {
    if ($gameMessage.isChoice()) {
		var choices = $gameMessage.choices();
		if ((choices[0]=='是'||choices[0]=='可') && choices[1]=='否'){
			this._choiceYNWindow.start();
		}else{
			this._choiceWindow.start();
		}
        return true;
    } else if ($gameMessage.isNumberInput()) {
        this._numberWindow.start();
        return true;
    } else if ($gameMessage.isItemChoice()) {
        this._itemWindow.start();
        return true;
    } else {
        return false;
    }
};
//=====================================================
// 对话窗口选择项：新增十字形按钮
//=====================================================
Window_Message.prototype.subWindows = function() {
    return [this._goldWindow, this._choiceWindow,
            this._numberWindow, this._itemWindow, this._choiceYNWindow];
};

Window_Message.prototype.isAnySubWindowActive = function() {
    return (this._choiceWindow.active ||
            this._numberWindow.active ||
            this._itemWindow.active ||
			this._choiceYNWindow.active);
};


SWDA_MsgChoiceWindow.Window_Message_CreateSubWindows = Window_Message.prototype.createSubWindows;
Window_Message.prototype.createSubWindows = function() {
	SWDA_MsgChoiceWindow.Window_Message_CreateSubWindows.call(this);
	this._choiceYNWindow = new Window_ChoiceYN(this);
	//this.addChildAt(this._choiceYNWindow,2);
};


//=====================================================
// 定义标准“可/否”选择项窗口
//=====================================================
/*
function Window_ChoiceYN() {
    this.initialize.apply(this, arguments);
}

Window_ChoiceYN.prototype = Object.create(Window_Command.prototype);
Window_ChoiceYN.prototype.constructor = Window_ChoiceYN;

Window_ChoiceYN.prototype.initialize = function(messageWindow) {
    this._messageWindow = messageWindow;
    Window_Command.prototype.initialize.call(this, 0, 0);
    this.openness = 0;
    this.deactivate();
    this._background = 0;
};
*/


function Window_ChoiceYN() {
    this.initialize.apply(this, arguments);
}
Window_ChoiceYN.prototype = Object.create(SWDA_Window_Command_4Arrows.prototype);
Window_ChoiceYN.prototype.constructor = Window_ChoiceYN;

Window_ChoiceYN.prototype.initialize = function(messageWindow) {
    this._messageWindow = messageWindow;
	
    SWDA_Window_Command_4Arrows.prototype.initialize.call(this, 0, 0);
    this.openness = 0;
    this.deactivate();
    this._background = 0;
	this.createButtons(SWDAWindowManager.YNButtonImage,808,477);
};

Window_ChoiceYN.prototype.start = function() {
    //this.updatePlacement();
    //this.updateBackground();
    this.refresh();
    this.selectDefault();
    this.open();
    this.activate();
	
};

Window_ChoiceYN.prototype.selectDefault = function() {
    //this.select($gameMessage.choiceDefaultType());
	this.select(1);
};


Window_ChoiceYN.prototype.updateBackground = function() {
    this._background = $gameMessage.choiceBackground();
    this.setBackgroundType(this._background);
};

Window_ChoiceYN.prototype.windowWidth = function() {
	return 0
    
};

Window_ChoiceYN.prototype.numVisibleRows = function() {
    return 0;
};


Window_ChoiceYN.prototype.textWidthEx = function(text) {
    return this.drawTextEx(text, 0, this.contents.height);
};

Window_ChoiceYN.prototype.contentsHeight = function() {
    return this.maxItems() * this.itemHeight();
};

Window_ChoiceYN.prototype.makeCommandList = function() {
    var choices = $gameMessage.choices();
	this.addCommand('', '', false);
	this.addCommand(choices[0], 'choice');
	this.addCommand('', '', false);
	this.addCommand(choices[1], 'choice');
};

Window_ChoiceYN.prototype.drawItem = function(index) {
    var rect = this.itemRectForText(index);
    this.drawTextEx(this.commandName(index), rect.x, rect.y);
};

Window_ChoiceYN.prototype.isCancelEnabled = function() {
    return $gameMessage.choiceCancelType() !== -1;
};

Window_ChoiceYN.prototype.isOkTriggered = function() {
    return Input.isTriggered('ok');
};

Window_ChoiceYN.prototype.callOkHandler = function() {
	if(this.index()==1)
		$gameMessage.onChoice(0);
	if(this.index()==3)
		$gameMessage.onChoice(1);
    this._messageWindow.terminateMessage();
    this.close();
};

Window_ChoiceYN.prototype.callCancelHandler = function() {
    $gameMessage.onChoice($gameMessage.choiceCancelType());
    this._messageWindow.terminateMessage();
    this.close();
};

